package com.naodong.shenluntiku.mvp.model.bean;

import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.google.gson.Gson;
import com.google.gson.JsonElement;

/**
 * Created by hujie on 17/5/22.
 */

public class CollectDetail implements MultiItemEntity {

    public static final int SUBJECT_ANALYSIS = 1;//单题解析
    public static final int VIDEO_ANALYSIS = 2;//视频解析
    public static final int SUBJECT = 3;//训练题


    private int favouriteId;
    private String favouriteTypeName;
    private String resourceType;
    private JsonElement resource;

    private Object collectDetail;

    public Object getCollectDetail() {
        if (collectDetail == null) {
            parseCollectDetail();
        }
        return collectDetail;
    }


    public String getResourceType() {
        return resourceType;
    }

    private void parseCollectDetail() {
        Gson gson = new Gson();
        if (CollectType.SUBJECTTYPE_NAME.equals(resourceType)) {
            collectDetail = gson.fromJson(resource, SubjectInfo.class);
        } else if (CollectType.VIDEOANALYSISTYPE_NAME.equals(resourceType) || CollectType.SUBJECTANALYSISTYPE_NAME.equals(resourceType)) {
            collectDetail = gson.fromJson(resource, Analysis.class);
        } else if ("".equals(resourceType)) {
        }
    }

    public void setCollectDetail(Object collectDetail) {
        this.collectDetail = collectDetail;
    }

    @Override
    public int getItemType() {
        if (CollectType.SUBJECTTYPE_NAME.equals(resourceType)) {
            return SUBJECT;
        } else if (CollectType.VIDEOANALYSISTYPE_NAME.equals(resourceType)) {
            return VIDEO_ANALYSIS;
        } else if (CollectType.SUBJECTANALYSISTYPE_NAME.equals(resourceType)) {
            return SUBJECT_ANALYSIS;
        }
        return SUBJECT;
    }
}
